package com.xbongbong.pro.enums.menu.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.MenuTypeEnum;
import com.xbongbong.pro.enums.AccessLinkEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

/**
 * @author 经销商
 * @version v1.0
 * @date 2020/12/21 10:44
 * @desrcption 经销商的菜单内容
 * @since v1.0
 */
@Getter
public enum DistributorMenuEnum {

    // 经销商
    DISTRIBUTOR("enum.distributorMenuEnum.name.distributor", XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getAlias(),  XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(),
            AccessLinkEnum.ALL_DISTRIBUTOR, "", MenuTypeEnum.FORM.getType()),
    // 联系人
    CONTACT("enum.distributorMenuEnum.name.contact", XbbRefTypeEnum.CONTACT.getAlias(),  XbbRefTypeEnum.CONTACT.getCode(),
            AccessLinkEnum.DISTRIBUTOR_CONTACT, "", MenuTypeEnum.FORM.getType()),
    // 跟进记录
    DISTRIBUTOR_COMMUNICATE("enum.distributorMenuEnum.name.distributor_communicate", XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getAlias(),
            XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), AccessLinkEnum.DISTRIBUTOR_COMMUNICATE, "", MenuTypeEnum.FORM.getType()),
    // 账号管理
    DISTRIBUTOR_ACCOUNT("enum.distributorMenuEnum.name.distributor_account", XbbRefTypeEnum.DISTRIBUTOR_ACCOUNT.getAlias(),  XbbRefTypeEnum.DISTRIBUTOR_ACCOUNT.getCode(),
            AccessLinkEnum.DISTRIBUTOR_ACCOUNT, "", MenuTypeEnum.FORM.getType()),
    ;

    /**
     * saas应用标示解释
     */
    private String name;
    /**
     * saas应用标示
     * @see XbbRefTypeEnum
     */
    private String alias;
    /**
     * @see XbbRefTypeEnum
     */
    private Integer code;
    /**
     * 对应的链接
     */
    private AccessLinkEnum accessLinkEnum;

    /**
     * 父节点，如果没有父节点，则此值为空字符串
     */
    private String parent;

    /**
     * 类型
     * @see MenuTypeEnum
     */
    private Integer type;


    DistributorMenuEnum(String name, String alias, Integer code, AccessLinkEnum accessLinkEnum, String parent, Integer type){
        this.name = name;
        this.alias = alias;
        this.code = code;
        this.accessLinkEnum = accessLinkEnum;
        this.parent = parent;
        this.type = type;
    }

    public static DistributorMenuEnum getByAlias(String alias) {
        for(DistributorMenuEnum crmMenuEnum: values()) {
            if(crmMenuEnum.getAlias().equals(alias)){
                return crmMenuEnum;
            }
        }
        return null;
    }

    public static DistributorMenuEnum getByCode(Integer code) {
        for(DistributorMenuEnum crmMenuEnum: values()) {
            if(crmMenuEnum.getCode().equals(code)){
                return crmMenuEnum;
            }
        }
        return null;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
